<template>
	<scroll-view show-scrollbar="false">
		<!-- 头像区域 -->
		<view class='su-center-bg'>
			<image :src='headData.img' 
					:lazy-load="true"
					class='su-head-img' 
					mode='aspectFill' 
					@click='showActionSheet=true'></image>
			<view class='text-xl'> 
				<text>{{headData.name}}</text>
				<text :class="['iconfont',showSex]" v-if='headData'></text>
			</view>
			<image src='https://gitee.com/476743842/app_image/raw/master/my/wave.gif' 
				   mode='scaleToFill' class='gif-wave'></image>
		</view>
		<!-- 发任务密码修改等 -->
		<view class='info-buttons'>
			<view class='su-flex su-button-active'>
				<view class="margin20">
					<text class='iconfont'>&#xe694;</text>
					<text>发任务</text>
				</view>
			</view>
			<view class='su-flex su-button-active'  >
				<view class="margin20">
					<text class='iconfont'>&#xe746;</text>
					<text>发消息</text>
				</view>
			</view>
		</view>
		<!-- 信息列表区 -->
		<view class="uni-card su-list" v-if="showPage"> 
			<view class="uni-list">
				<view class="uni-list-cell" >
					<view class="su-list-icon">
						<text class='iconfont' style='color:#31BBFF;'>&#xe6a2;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">所属机构</text>
						<text class='text-content text-sm'>{{infoData.currentOgnName||"未设置所属机构"}}</text>
					</view>
				</view>
				<view class="uni-list-cell" >
					<view class="su-list-icon">
						<text class='iconfont' style='color:#30C462;'>&#xe69d;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">所属部门</text>
						<text class='text-content text-sm'>
							{{infoData.currentDeptName||"未设置所属部门"}}
						</text>
					</view>
				</view>
				<view class="uni-list-cell" >
					<view class="su-list-icon">
						<text class='iconfont' style='color:#FAA727;'>&#xe696;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">当前岗位</text>
						<text class='text-content text-sm'>{{infoData.currentPositionName||"未设置当前岗位"}}</text>
					</view>
				</view>
				<view class="uni-list-cell" @click="_callPhone">
					<view class="su-list-icon">
						<text class='iconfont' style='color:#31BBFF;'>&#xe698;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">手机号码</text>
						<text class='text-content text-sm'>{{infoData.mobilePhoneNum||"未填写"}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="su-list-icon">
						<text class='text-grey iconfont' 
							  style='color:#F15A49;font-size:30upx;'>&#xe69b;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">电子邮箱</text>
						<text class='text-content text-sm'>{{infoData.mail||"未填写"}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="su-list-icon">
						<text class='text-grey iconfont' style='color:#31BBFF;'>&#xe69e;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">QQ</text>
						<text class='text-content text-sm'>{{infoData.sqq||"未填写"}}</text>
					</view>
				</view>
				<view class="uni-list-cell">
					<view class="su-list-icon">
						<text class='iconfont' style='color:#888;'>&#xe697;</text>
					</view>
					<view class="uni-list-cell-navigate">
						<text class="text-title">居住地址</text>
						<text class='text-content text-sm'>{{infoData.sfamilyaddress||"未填写"}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 弹出组件 -->
		<actionsheet tips="请选择" :show="showActionSheet"
					 :item-list="sheetData" @click="_sheetClick"
					 @cancel="showActionSheet=false"></actionsheet>
		<message ref="message"></message>
		<!-- 加载中组件 -->
		<loading ref="loading"></loading>
	</scroll-view> 
</template>

<script>
	/**
	 * 个人资料页
	 */
	import actionsheet from "@/components/su-saui/su-actionsheet/actionsheet"
	export default {
		components:{
			actionsheet
		},
		data() {
			return {
				headData: {},
				infoData:{},
				sheetData:[],
				showActionSheet:false,		//是否显示sheet
				showPage:false
			};
		}, 
		computed:{
			showSex(){
				if(this.infoData['sex']=="男") 
					return "icon-nan su-icon-boy"
				else if(this.infoData['sex']=="女") 
					return "icon-nv su-icon-girl"
				else 
					return "icon-nan su-icon-boy"
			}
		},
		onLoad(params) {
			if(!params['pid']) {
				uni.core.message("参数错误","error")
				setTimeout(()=>{
					uni.navigateBack()
				},1500)
			}
			this.init()
			/*获取上下文 */
			this._bid = uni.core.bsessionid
			this._personId = params['pid']
			this._personName = params['pname']
			setTimeout(()=>{
				/*加载头像 */
				this._loadHead(this._bid,params['pcode'])
				/*加载个人资料*/ 
				if(uni.p9version=="old"){
					this._loadPersonInfo()
				}else {
					this._loadPersonInfo2()
				}
			},10)
		},
		methods:{
			/*加载头像 */
			_loadHead (_bid,_code) {
			    var time = new Date().getTime()
				var _url = "{0}/system/user/userPhotoDownloadAction?bsessionid={1}&code={2}&t={3}"
				_url = uni.core.strFormat(_url,uni.core.rootPath,_bid,_code,time)
			    this.headData = {
					name: this._personName,
					img: _url
			    }
			},
			/*加载个人信息*/
			_loadPersonInfo(){
				var params = {personID:this._personId}
				uni.core.showLoading()
				uni.core.post("/queryPsnFullInfoAction",params,(data,flag,msg)=>{ 
					if(flag){
						var personData = data['data']['psn']
						var orgData = data['data']['orgs'][0]
						this.infoData = {
							...personData
						} 
						//设置组织信息
						var {fullName,kind} = orgData
						var names = fullName.split("/")
						var info = this.infoData
						info['currentOgnName'] = names[1]
						if(kind=='pos'){
							info['currentPositionName'] = names[names.length-1]
							if(names[names.length-2]!=names[1]){
								info['currentDeptName'] = names[names.length-2]
							}
						}else if(kind=='dept'){
							info['currentDeptName'] = names[names.length-1]
						}
						this.showPage = true;
					}else{
						uni.core.message("用户信息查询错误","error")
						setTimeout(()=>{
							uni.navigateBack()
						},1500)
					}
					uni.core.hideLoading()
				})
			},
			/*6.5版本的加载其他人的数据*/
			_loadPersonInfo2(){
				var dataConfig = {
					queryAction:{
						url : "/bsys/org/queryPersonByIdAction",
						param:{
							id:this._personId
						}
					}
				}
				var personData = uni.simpleData.creat("personData",dataConfig,this)
				personData.refreshData((data,flag)=>{
					if(flag){
						
					}
				})
			},
			_callPhone(){
				uni.makePhoneCall({
					phoneNumber:this.infoData['mobilePhoneNum']
				})
			},
			/*弹出框的回调*/
			_sheetClick(itemIndex){
				var {index} = itemIndex
				switch (index*1){
					case 0:
						uni.previewImage({
							urls:[this.headData['img']]
						})
						break
				}
				this.showActionSheet = false
			},
			/*定义一些配置变量 */
			init(){
				this._code = null,this._bid = null,this._personId=null
				this._personName = null
				/*弹出窗口配置*/
				this.sheetData = ["查看大头像"]
			},
			_toView:uni.core.openPage
		}
	}
</script>

<style lang="scss">
	@import "./index.scss";
</style>
